/**
 * Copyright (C)  Gadglet .
 *
 * This file is part of Gadglet
 *
 * Gadglet is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Gadglet is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with Gadglet. If not, see <http://www.gnu.org/licenses/>.
 */

package com.gadglet.data;


import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import javax.jdo.annotations.Extension;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.Key;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import javax.jdo.annotations.Value;

import com.gadglet.core.GadgletRequestWrapper;
import com.gadglet.params.ProfPrivacyStatus;
import com.gadglet.params.ProfileFields;

/**
 * 
 * Persistence class for open social users  (NOT Google Apps accounts!)
 *
 */
@PersistenceCapable
public class UserProfile implements Serializable {
	
	private static final long serialVersionUID = -2061224335928089248L;

	
	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	@Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
	private String profileId;
	
	
	@Persistent
	private Date creation;
	
	@Persistent
	private String openSocialViewerId;
	
	@Persistent
	private String consumerKey;
	
	@Persistent
	private String nickName;
	
	@Persistent
	private String photoUrl; 
	
	@Persistent
	private ProfPrivacyStatus privacyStatus;
	
	@Persistent(serialized = "true")
	@Key(types=String.class) @Value(types=Object.class)
	private Map <String, Object> customParams = new HashMap<String, Object>();


	public UserProfile(GadgletRequestWrapper platformRequestWrapper) {
		
		this.openSocialViewerId = platformRequestWrapper.getOpenSocialViewerId();
		this.consumerKey = platformRequestWrapper.getOpenSocialConsumerKey();
		this.creation = new java.util.Date();
		this.nickName = platformRequestWrapper.getParameter(ProfileFields.PROFILE_NICKNAME.getParamName());
		this.privacyStatus = platformRequestWrapper.getProfilePrivacy();
		this.photoUrl = platformRequestWrapper.getParameter(ProfileFields.PROFILE_THUMBNAILURL.getParamName());
	}
	
	public String getPhotoUrl() {
		return photoUrl;
	}
	
	public void setPhotoUrl(String  photoUrl) {
		 this.photoUrl = photoUrl;
	}
	
	

	public String getNickName() {
		return nickName;
	}

	public void setNickName(String nickName) {
		this.nickName = nickName;
	}

	public ProfPrivacyStatus getVisibilityStatus() {
		return privacyStatus;
	}

	public void setPrivacyStatus(ProfPrivacyStatus visibilityStatus) {
		this.privacyStatus = visibilityStatus;
	}

	public Map <String, Object> getCustomParams() {
		return customParams;
	}

	public void setCustomParams(HashMap <String, Object> customParams) {
		this.customParams = customParams;
	}

	public String getProfileId() {
		return profileId;
	}

	public Date getCreation() {
		return creation;
	}

	public String getOpenSocialViewerId() {
		return openSocialViewerId;
	}

	public String getConsumerKey() {
		return consumerKey;
	}
	
	public boolean isPrivate(){
		if (privacyStatus.equals(ProfPrivacyStatus.PRIVATE))
			return true;
		else
			return false;
	}
	
	public boolean isProtected(){
		if (privacyStatus.equals(ProfPrivacyStatus.PROTECTED))
			return true;
		else
			return false;
	}
	
	public boolean isPublic(){
		if (privacyStatus.equals(ProfPrivacyStatus.PUBLIC))
			return true;
		else
			return false;
	}
	
}
